<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>按要求组成数组</title>
</head>
<body>
<script>
    let arr = [2, 10, 3, 4, 5, 11, 10, 11, 20];
    function arrGroup(res) {
        let arr = [];
        let result = [];
        let i = 0;
        for (let i = 0; i < res.length; i++) {
            if (arr.indexOf(res[i]) === -1) {
                arr.push(res[i])
            }
        }
        for (let j = 0; j < arr.length - 1; j++) {
            for (let k = 0; k < arr.length - 1 - j; k++) {
                if (arr[k] > arr[k + 1]) {
                    let temp = arr[k];
                    arr[k] = arr[k + 1];
                    arr[k + 1] = temp;
                }
            }
        }
        result[i] = [arr[0]];
        arr.reduce(function (prev, cur) {
            cur - prev === 1 ? result[i].push(cur) : result[++i] = [cur];
            return cur;
        });
        for (let i = 0; i < 10; i++) {
            result[i] = Math.random() * 20 | 0;
        }
        return result;
    }
    console.log(...arrGroup(arr));
</script>
</body>
</html>